/************************************************************************************
**  
* @copyright (c) 2015-, Technology Co., LTD. All Right Reserved.
*
*************************************************************************************/
/**
* @file     duye_cap_engine.h
* @version     
* @brief      
* @author   
* @date     2013-01-14
* @note 
*
*  1. 2018-01-14 created this file
* 
*/
#pragma once

#include <list>
#include <map>
#include <string>

#include <duye_if_dev.h>
#include <duye_cap_service_base.h>
#include <duye_cap_plugin.h>
#include <duye_cap_transfer.h>

namespace duye {

/**
 * @brief plugin list<DataServiceType, WdpiService*>
 */
typedef std::map<const DataServiceType, CapDataService*> DataServiceContainer;

/**
 * @brief plugin map<pluginName, PluginInfo>
 */
typedef std::map<const std::string, PluginInfo*> PluginContainer;

/**
 * @brief net layer server interface
 */
class CapEngine : public CapService, public Singleton<CapEngine> {
public:
    ~CapEngine();

	// implementation WdpiService interface 
	virtual bool start();
	// implementation WdpiService interface      
    virtual bool stop();

    /**
     * @brief add plugin
     * @param [in] pluginName : the plugin name
     * @param [in] pluginPath : the plugin dynamic file full path
	 * @param [in] transfer : plugin transfer data to others module or network
     * @return true/false
     */
    bool addPlugin(const std::string& pluginName, const std::string& pluginPath, ModuleTransfer* transfer);

    /**
     * @brief add plugin object
	 * @param [in] pluginName : the plugin name
     * @param [in] pluginObj : plugin object
	 * @param [in] transfer : plugin transfer data to others module or network
     * @return true/false
     */
    bool addPluginObj(const std::string& pluginName, AppPlugin* pluginObj, ModuleTransfer* transfer);

    /**
     * @brief delete plugin
     * @param [in] pluginName : the plugin name
     */    
    void delPlugin(const std::string& pluginName);

    /**
     * @brief add interface
     * @param [in] interface : interface
     */    
    void addInterface(const NetIfDev& ifDev);

    /**
     * @brief add cap file
     * @param [in] ifName : interface name
     */    
    void addCapFile(const std::string& capFilePath);

	/**
     * @brief get default interface ip
     */    
    std::string getCurrentIfIp();

private:
    CapEngine();

	// implementation sys::ThreadTask interface
	virtual bool run();		

	// load plugin library
	bool loadPlugin(const std::string& pluginName, 
		const std::string& pluginPath, 
		PluginInfo& pluginInfo);

	// startup service
	bool startupService();

	// get data service
	CapDataService* getDataService(const DataServiceType type);

private:
    DataServiceContainer m_dataServiceContainer;
    PluginContainer m_pluginContainer;
	std::list<std::string> m_ifNameList;
	std::list<std::string> m_ifIpList;
	std::list<std::string> m_capFileList;
};

}
